PY_PKG_FOLDER_NAME=$1
if [ -z "$PY_PKG_FOLDER_NAME" ]; then
  PY_PKG_FOLDER_NAME="coin2_py_pkg"
fi

COIN_ROOT="$(git rev-parse --show-toplevel)"
PY_PKG_ROOT=$COIN_ROOT/../$PY_PKG_FOLDER_NAME
echo "coin2_py_pkg path:$PY_PKG_ROOT"

export build_njobs=${build_njobs:-18}
bazel build -j ${build_njobs} -c opt --strip=always //cc/appcoin2/support/symbology:py_symbology.so
bazel build -j ${build_njobs} -c opt --strip=always //cc/appcoin2/support/order:py_parser.so
bazel build -j ${build_njobs} -c opt --strip=always //cc/appcoin2/support/order:py_trade_client.so
bazel build -j ${build_njobs} -c opt --strip=always //cc/appcoin2/support/feed:py_market_data_client.so
bazel build -j ${build_njobs} -c opt --strip=always //cc/appcoin2/support/py_module:py_driver.so



function deploy_coin2_app {
  mkdir -p $PY_PKG_ROOT/$1
  rsync -avh --delete -L $COIN_ROOT/bazel-bin/$1/$2 $PY_PKG_ROOT/$1/
}

function deploy_coin2_py {
  mkdir -p $PY_PKG_ROOT/$1
  rsync -avh $3 --delete -L $COIN_ROOT/python/$1/$2 $PY_PKG_ROOT/$1/
}

function deploy_coin2_file {
  mkdir -p $PY_PKG_ROOT/$1
  rsync -avh $3 --delete -L $COIN_ROOT/$1/$2 $PY_PKG_ROOT/$1/
}

set -x
deploy_coin2_app cc/appcoin2/support/symbology py_symbology.so
deploy_coin2_app cc/appcoin2/support/feed py_market_data_client.so
deploy_coin2_app cc/appcoin2/support/order py_trade_client.so
deploy_coin2_app cc/appcoin2/support/order py_parser.so
deploy_coin2_app cc/appcoin2/support/py_module py_driver.so

deploy_coin2_file cc/appcoin2/strategy py_strat

deploy_coin2_py coin/proto coin_market_enums_pb2.py
deploy_coin2_py coin/proto coin_meta_service_pb2_grpc.py
deploy_coin2_py coin/proto coin_meta_service_pb2.py
deploy_coin2_py coin/proto coin_request_pb2.py

deploy_coin2_py coin2/exchange product_info.py
deploy_coin2_py coin2/exchange symbology.py

deploy_coin2_py coin2/service feed

deploy_coin2_py coin2/support product_info

echo "Build and Copy to $PY_PKG_ROOT Successfully!!"
echo "You must push your change later!!"
